.text
.section .rodata
.align 8
.LC0:
        .string "x in outer block: %d at %p\n"
.LC1:
        .string "x in inner block: %d at %p\n"
.LC2:
        .string "x in while loop: %d at %p\n"

.text
.globl main
.type main, @function
main:
    addi sp, sp, -32
    sd ra, 24(sp)
    sd s0, 16(sp)

    // 分配局部变量，跟x86一样，分配2个地址
    // 外部x:-4(s0)
    // block和while中的x: -8(s0)
    li a5, 30
    sw a5, -4(s0) /* 外部的x */
    mv a1, a5
    addi a2, s0, -4
    lui a5, %hi(.LC0)
    addi a0, a5, %lo(.LC0)
    call printf

    // ##### 进入block
    li a5, 77
    sw a5, -8(s0) /* block和while中的x */
    mv a1, a5
    addi a2, s0, -8
    lui a5, %hi(.LC1)
    addi a0, a5, %lo(.LC1)
    call printf
    // ##### 退出block

    lw a1, -4(s0) /* 外部的x */
    addi a2, s0, -4
    lui a5, %hi(.LC0)
    addi a0, a5, %lo(.LC0)
    call printf

    j .WHILE_11_COMPARE
.WHILE_11_ENTER:
    li a5, 100
    sw a5, -8(s0) /* block和while中的x */
    lw a5, -8(s0) /* block和while中的x */
    addiw a5, a5, 1
    sw a5, -8(s0) /* block和while中的x */
    mv a1, a5
    addi a2, s0, -8
    lui a5, %hi(.LC2)
    addi a0, a5, %lo(.LC2)
    call printf 
.WHILE_11_COMPARE:
    lw a5, -4(s0) /* 外部的x */
    addiw a4, a5, 1
    sw a4, -4(s0) /* 外部的x */
    sext.w a5, a5
    li a6, 33
    blt a5, a6, .WHILE_11_ENTER

    lw a1, -4(s0) /* 外部的x */
    addi a2, s0, -4
    lui a5, %hi(.LC0)
    addi a0, a5, %lo(.LC0)
    call printf

    ld ra, 24(sp)
    ld s0, 16(sp)
    addi sp, sp, 32
    jr ra